﻿@model NewsItemListModel
@{
    var defaultGridPageSize = EngineContext.Current.Resolve<Nop.Core.Domain.Common.AdminAreaSettings>().DefaultGridPageSize;
    var gridPageSizes = EngineContext.Current.Resolve<Nop.Core.Domain.Common.AdminAreaSettings>().GridPageSizes;

    //page title
    ViewBag.Title = T("Admin.ContentManagement.News.NewsItems").Text;
}
<div class="section-header">
    <div class="title">
        <img src="@Url.Content("~/Administration/Content/images/ico-content.png")" alt="" />
        @T("Admin.ContentManagement.News.NewsItems")
    </div>
    <div class="options">
        <a href="@Url.Action("Create")" class="k-button">@T("Admin.Common.AddNew")</a>
    </div>
</div>
<table width="100%">
    <tr>
        <td class="adminTitle">
            @Html.NopLabelFor(model => model.SearchStoreId):
        </td>
        <td class="adminData">
            @Html.DropDownList("SearchStoreId", Model.AvailableStores)
        </td>
    </tr>
    <tr>
        <td colspan="2">
            <input type="button" id="search-newsitem" class="k-button" value="@T("Admin.Common.Search")" />
        </td>
    </tr>
</table>
<table class="adminContent">
    <tr>
        <td>
            <div id="newsitem-grid"></div>

            <script>
    $(document).ready(function () {
        $("#newsitem-grid").kendoGrid({
            dataSource: {
                type: "json",
                transport: {
                    read: {
                        url: "@Html.Raw(Url.Action("List", "News"))",
                        type: "POST",
                        dataType: "json",
                        data: additionalData
                    }
                },
                schema: {
                    data: "Data",
                    total: "Total",
                    errors: "Errors"
                },
                error: function(e) {
                    display_kendoui_grid_error(e);
                    // Cancel the changes
                    this.cancelChanges();
                },
                pageSize: @(defaultGridPageSize),
                serverPaging: true,
                serverFiltering: true,
                serverSorting: true
            },
            pageable: {
                refresh: true,
                pageSizes: [@(gridPageSizes)]
            },
            editable: {
                confirmation: false,
                mode: "inline"
            },
            scrollable: false,
            columns: [{
                field: "Title",
                title: "@T("Admin.ContentManagement.News.NewsItems.Fields.Title")"
            }, {
                field: "LanguageName",
                title: "@T("Admin.ContentManagement.News.NewsItems.Fields.Language")",
                width: 200,
            }, {
                field: "Comments",
                title: "@T("Admin.ContentManagement.News.NewsItems.Fields.Comments")",
                width: 100,
                template: '<a href="Comments?filterByNewsItemId=#=Id#">@T("Admin.ContentManagement.News.NewsItems.Fields.Comments") - #=Comments# </a>'
            }, {
                field: "StartDate",
                title: "@T("Admin.ContentManagement.News.NewsItems.Fields.StartDate")",
                width: 200,
                type: "date",
                format: "{0:G}"
            }, {
                field: "EndDate",
                title: "@T("Admin.ContentManagement.News.NewsItems.Fields.EndDate")",
                width: 200,
                type: "date",
                format: "{0:G}"
            }, {
                field: "Published",
                title: "@T("Admin.ContentManagement.News.NewsItems.Fields.Published")",
                width: 100,
                headerAttributes: { style: "text-align:center" },
                attributes: { style: "text-align:center" },
                template: '<img src="@Url.Content("~/Administration/Content/images/")active-#=Published#.gif" />'
            }, {
                field: "CreatedOn",
                title: "@T("Admin.ContentManagement.News.NewsItems.Fields.CreatedOn")",
                width: 200,
                type: "date",
                format: "{0:G}"
            }, {
                field: "Id",
                title: "@T("Admin.Common.Edit")",
                width: 100,
                template: '<a href="Edit/#=Id#">@T("Admin.Common.Edit")</a>'
            }]
        });
    });
            </script>
            <script type="text/javascript">

                $(document).ready(function () {
                    //search button
                    $('#search-newsitem').click(function () {
                        //search
                        var grid = $('#newsitem-grid').data('kendoGrid');
                        grid.dataSource.page(1); //new search. Set page size to 1
                        //grid.dataSource.read(); we already loaded the grid above using "page" function
                        return false;
                    });
                });

                function additionalData() {
                    return {
                        SearchStoreId: $('#SearchStoreId').val()
                    };
                }
            </script>
        </td>
    </tr>
</table>

